package com.ithe;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {
    public static <Student> void main(String [] args) {

        ArrayList<String> list = new ArrayList<>();
        list.add("天天");
        list.add("天天");
        list.add("天天");
        System.out.println(list);
        System.out.println(new HashSet<String>(list));
        ArrayList<String> newlist = new ArrayList<>(new ArrayList<String>(list));

        //1
        HashSet<String> hashSet = new HashSet<>();
        //2
        hashSet.add("小明");
        hashSet.add("天天");
        hashSet.add("张三");
        hashSet.add("李明");
        System.out.println(hashSet);

        //3取数据（迭代器)
        Iterator<String> iterator= hashSet.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }

//        for (int i = 0; i < hashSet.size(); i++) {
//
//        }       不能用

        //4取数据（增强for循环）   语法糖
        for (String name : hashSet) {
            System.out.println("name" + name);
        }

        int[] arr = {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            System.out.println(arr);
        }
        hashSet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

            hashSet.forEach(System.out::println);

    }
}
